//
//  TFDashView.m
//  YunKang
//
//  Created by leoking870 on 2017/9/26.
//  Copyright © 2017年 leoking870. All rights reserved.
//

#import "YKDashView.h"

IB_DESIGNABLE
@implementation YKDashView

- (instancetype)init {
    if (self = [super init]) {
        self.lineWidth = 2;
        self.lineColor = [UIColor redColor];
        self.dashLineLength = 3;
        self.backgroundColor = [UIColor clearColor];
    }
    return self;
}

// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    [super drawRect:rect];
    // Drawing code
    CGContextRef context =UIGraphicsGetCurrentContext();
    // 设置线条的样式
    CGContextSetLineCap(context, kCGLineCapRound);
    // 绘制线的宽度
    CGContextSetLineWidth(context, self.lineWidth);
    // 线的颜色
    CGContextSetStrokeColorWithColor(context, self.lineColor.CGColor);
    // 开始绘制
    CGContextBeginPath(context);
    // 设置虚线绘制起点
    CGContextMoveToPoint(context, 0, rect.size.height/2);
    // lengths的值｛10,10｝表示先绘制10个点，再跳过10个点，如此反复
    CGFloat lengths[] = {self.dashLineLength,self.dashLineLength};
    // 虚线的起始点
    CGContextSetLineDash(context, 0, lengths,2);
    // 绘制虚线的终点
    CGContextAddLineToPoint(context, rect.size.width,rect.size.height/2);
    CGContextDrawPath(context, kCGPathStroke);
}


@end
